/*
 * @Descripttion: 
 * @version: 
 * @Author: kl2018
 * @Date: 2019-03-07 20:06:20
 * @LastEditors: kl2018
 * @LastEditTime: 2020-06-23 10:06:41
 */
import { WeaLocaleProvider } from 'ecCom';
import { toJS } from "mobx";
const getLabel = WeaLocaleProvider.getLabel;

import * as odocUtil from '../util/odocUtil';

//接收config对象
/**
 *config结构为
 *{
 * compStore,
 * tableStore
 * }
 */


function getShowCustomedColMenu(config) {
	const { compStore, tableStore } = config;
	return {
		key: 'colSet',
		icon: <i className='icon-coms-Custom' />,
		content: getLabel('382660', '显示定制列'),
		onClick: key => {
			odocUtil.onColSetBtnClick(compStore, tableStore);
		}
	}
}

//接收config对象
/**
 *config结构为
 *{
 * compStore,
 * tableStore
 * }
 */
function getSearchButtonOfRightMenu(config) {
	const { compStore, viewconditiondomkey } = config;
	return {
		key: 'search',
		icon: <i className='icon-coms-search' />,
		content: getLabel('388113', '搜索'),
		// disabled: selectedRowKeys.length === 0 ? true : false,
		onClick: key => {
			odocUtil.onSearchBtnClick(compStore, viewconditiondomkey)
			// todo const dataKey = CompStore.dataKey;
			// tableStore.setColSetVisible(dataKey,true);
			// tableStore.tableColSet(dataKey,true);
		}
	}
}

//那些用于操作表格的右键菜单按钮，比如可能是批量删除、添加等
//接收config对象
/**
 *config结构为
 *
 */
function getOperateTableButtonOfRightMenuMenu(config) {
	const { buttonKey, iconClassName, buttonText, compStore, needCheck, onClick } = config;
	return {
		key: buttonKey,
		icon: <i className={iconClassName} />,
		content: buttonText,
		disabled: needCheck ? toJS(compStore.selectRowId).length === 0 ? true : false : false,
		onClick: key => {
			// const selectedRowKeys = getSelectedRowKeys (compStore, tableStore);
			// todo onClick(selectedRowKeys, compStore, tableStore);
			onClick();
			// tableStore.setColSetVisible(dataKey,true);
			// tableStore.tableColSet(dataKey,true);
		}
	}
}



//configs是一个数组，每个数组元素(config)的结构参见
// getOperateTableButtonOfRightMenuMenu和getSearchButtonOfRightMenu
//getShowCustomedColMenu
export default function (configs) {
	const buttonArr = [];

	configs.forEach((config) => {

		//不是搜素、显示定制列这些特殊的菜单按钮时
		if (config.buttonKey !== 'colSet' && config.buttonKey !== 'search') {
			buttonArr.push(getOperateTableButtonOfRightMenuMenu(config));

		} else if (config.buttonKey == 'colSet') {
			buttonArr.push(getShowCustomedColMenu(config));

		} else if (config.buttonKey == 'search') {
			buttonArr.push(getSearchButtonOfRightMenu(config));
		}
	});

	return buttonArr;
}